import pathlib
import confuse


def validate_config(config: confuse.Configuration) -> bool:
    zoomeye = config['api']['zoomeye']
    over_num = len(zoomeye['username'].get()) - len(zoomeye['password'].get())
    if over_num != 0:
        print('zoomeye 配置错误')
        return False
    return True


PACKAGE_PATH = pathlib.Path(__file__).parent.parent
CONFIG = confuse.Configuration('Meteor')
CONFIG.set_file(PACKAGE_PATH / 'config/api.yaml')
validate_config(CONFIG)

# API配置
VT_KEY = CONFIG['api']['virustotal']['key']
SHODAN_API = CONFIG['api']['shodan']['key']
SHODAN_SAVE_PATH = PACKAGE_PATH / 'tmp/shodan'

ZOOMEYE_SAVE_PATH = PACKAGE_PATH / CONFIG['api']['zoomeye']['tmp_path'].get()
ZOOMEYE_AUTH = list(zip(CONFIG['api']['zoomeye']['username'], CONFIG['api']['zoomeye']['password']))

AWVS_API = CONFIG['api']['awvs']['key'][0].get()
AWVS_URL = CONFIG['api']['awvs']['url'][0].get()


# 第三方工具配置
GOBY_SETTINGS = {
    'api_url': CONFIG['thirdtools']['goby']['api_url'][0].get(),
    'user': CONFIG['thirdtools']['goby']['user'][0].get(), 
    'password': CONFIG['thirdtools']['goby']['password'][0].get()
}

# 杂项配置
MIN_NETWORK_NUM = CONFIG['misc']['min_network_num'].get(int)
CACHE_PATH = PACKAGE_PATH / 'tmp/cache.db'
TMP_SAVE_PATH = PACKAGE_PATH / 'tests/res'
# 第三方软件配置
HTTPX_EXEC_PATH = PACKAGE_PATH / CONFIG['thirdtools']['httpx']['path'][0].get(str)

# 本地单元测试使用的API
AWVS_TEST_API = '1986ad8c0a5b3df4d7028d5f3c06e936c087fb23533214efcb1e0d92623d7128f'
GOBY_TEST_API = 'http://127.0.0.1:8361'